<?php

use \yii\helpers\ArrayHelper;

$customMenu = include __DIR__ . "/menu-project.php";

$defaultMenuItems = [
    [
        'label' => 'RBAC管理',
        'url' => '#',
        'icon' => 'fa fa-gavel',
        'items' => [
            [
                'label' => '用户管理',
                'url' => ['/user/default/index'],
                'match' => '@^/user/default.*@',
                'auth'=> [
                    'route:user/default/index',
                    'route:user/default/create',
                    'route:user/default/update',
                    'route:user/default/delete',
                    'route:user/default/batch-delete',
                ]
            ],
            [
                'label' => '用户组管理',
                'url' => ['/user/group/index'],
                'auth'=> [
                    'route:user/group/index',
                    'route:user/group/save',
                    'route:user/group/manage',
                    'route:user/group/remove',
                    'route:user/group/move',
                ]
            ],
            [
                'label' => '权限列表',
                'url' => ['/user/permission/index'],
                'auth' => [
                    'route:user/permission/index',
                    'route:user/permission/create',
                    'route:user/permission/update',
                    'route:user/permission/delete',
                    'route:user/permission/batch-delete',
                ]
            ],
            [
                'label' => '扫描权限',
                'url' => ['/user/permission/scan'],
                'auth' => [
                    'route:user/permission/scan',
                ]
            ],
            [
                'label' => '新增权限',
                'url' => ['/user/permission/create'],
                'visible' => false,
                'auth' => [
                    'route:user/permission/create',
                ]
            ],
            [
                'label' => '角色列表',
                'url' => ['/user/role/index'],
                'auth' => [
                    'route:user/role/index',
                    'route:user/role/create',
                    'route:user/role/update',
                    'route:user/role/delete',
                    'route:user/role/batch-delete',
                ]
            ],
            [
                'label' => '新增角色',
                'url' => ['/user/role/create'],
                'visible' => false,
                'auth' => [
                    'route:user/role/create',
                ]
            ],
            [
                'label' => '规则列表',
                'url' => ['/user/rule/index'],
                'auth' =>[
                    'route:user/rule/index',
                    'route:user/rule/create',
                    'route:user/rule/delete',
                    'route:user/rule/batch-delete',
                ]
            ],
            [
                'label' => '新增规则',
                'url' => ['/user/rule/create'],
                'visible' => false,
                'auth' => [
                    'route:user/rule/create',
                ]
            ],
        ]
    ],
    [
        'label' => '日志审查',
        'url' => ['#'],
        'icon' => 'fa fa-eye',
        'items' => [
            [
                'label' => '路由审查',
                'url' => ['/audit/entry/index'],
                'auth' =>[
                    'route:audit/entry/db-explain',
                    'route:audit/entry/index',
                    'route:audit/entry/view',
                ]
            ],
            [
                'label' => '模型审查',
                'url' => ['/audit/trail/index'],
                'auth' =>[
                    'route:audit/trail/index',
                    'route:audit/trail/view',
                ]
            ],
            [
                'label' => '发信审查',
                'url' => ['/audit/mail/index'],
                'auth' =>[
                    'route:audit/mail/index',
                    'route:audit/mail/view',
                    'route:audit/mail/download',
                ]
            ],
            [
                'label' => 'JS审查',
                'url' => ['/audit/javascript/index'],
                'auth' =>[
                    'route:audit/javascript/index',
                    'route:audit/javascript/view',
                ]
            ],
            [
                'label' => '错误审查',
                'url' => ['/audit/error/index'],
                'auth' =>[
                    'route:audit/error/index',
                    'route:audit/error/view',
                ]
            ],
            [
                'label' => '信息统计',
                'url' => ['/audit'],
                'auth' =>[
                    'route:audit/default/index',
                ]
            ],
        ]
    ],
    [
        'label' => '系统配置',
        'url' => ['/setting'],
        'icon' => 'fa fa-cog',
        'auth'=> [
            'module:setting',
        ]
    ],
];


if (!empty($customMenu))
{
    $menuItems = ArrayHelper::merge($customMenu,$defaultMenuItems);
}

$dashboard = [
    'label' => $this->t('Dashboard'),
    'url' => Yii::$app->homeUrl,
    'icon' => 'fa-dashboard',
    'active' => Yii::$app->request->url === Yii::$app->homeUrl
];

array_unshift($dashboard,$menuItems);

return $menuItems;
